#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/fs.h>
#include<linux/slab.h>
#include<linux/interrupt.h>

MODULE_AUTHOR("Tan xujia");
MODULE_LICENSE("Dual BSD/GPL");

struct mem {
    int count;
    int size;
};

struct kmem_cache *p;

static int
__init mem_init(void)
{
    printk("init\n");
    p = kmem_cache_create("memtest", sizeof(struct mem), 0,
         SLAB_HWCACHE_ALIGN, NULL);
    if(!p){
        return -1;
    }else {
        struct mem *p1 = (struct mem*)kmem_cache_alloc(p, GFP_KERNEL);
        p1->count = 10;
        p1->size = 12;
        printk("p1->count = %d, p1->size = %d\n",
           p1->count, p1->size);
        kmem_cache_free(p, p1);     
    }  
    return 0;
}

static void
__exit mem_exit(void)
{
    printk("exit\n");
    kmem_cache_destroy(p);
    p = NULL;
    return;
}

module_init(mem_init);
module_exit(mem_exit);
